<?php

namespace App\Common\Model\Base;

use App\Common\Model\Attribute\CreateSql;
use App\Common\Model\Attribute\InitData;
use App\Common\Model\Model;


/**
 * 超级配置
 * @property int    $id           ID
 * @property string $sign         配置的签名
 * @property string $name         配置的名称
 * @property int    $type         配置的类型
 * @property array  $config_info  配置详情
 * @property array  $config_value 配置值
 * @property string $create_time  创建时间
 * @property string $update_time  更新时间
 * @property int    $delete_time  删除时间
 */
#[CreateSql(<<<SQL
CREATE TABLE `sc_super_config` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `sign` varchar(32) NOT NULL DEFAULT '' COMMENT '配置的签名',
  `name` varchar(32) NOT NULL DEFAULT '' COMMENT '配置的名称',
  `type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '配置的类型：1=单项组，2=数组，3=键值对,4=高级数组',
  `config_info` json DEFAULT NULL COMMENT '配置详情',
  `config_value` json DEFAULT NULL COMMENT '配置值',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `sign` (`sign`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='超级配置';
SQL)]
#[InitData([
    ['id' => 1, 'sign' => 'single', 'name' => '单项', 'type' => 1, 'config_info' => '[{"extra": [], "field": "t", "group": "x=X", "title": "文字", "search": "0", "formType": "text"}, {"extra": ["1=ww", "2=rer"], "field": "x", "group": "x=X", "title": "单选", "search": "0", "formType": "radio"}, {"list": "", "extra": ["1=xxx", "2=sdsasda"], "field": "rx", "group": "x=X", "title": "单选2", "search": "", "formType": "radio"}, {"extra": [], "field": "r", "group": "VV", "title": "颜色", "search": "0", "formType": "color"}, {"extra": ["role:id=name"], "field": "b", "group": "VV", "title": "表", "search": "0", "formType": "select"}, {"extra": [], "field": "e", "title": "服务文本", "search": "0", "formType": "editor"}, {"extra": [], "field": "i", "title": "简介", "search": "0", "formType": "textarea"}]', 'config_value' => '{"b": 2, "e": "", "i": "sdfsdf sdf", "r": "#9D4E4E", "x": [{"t": "234234", "x": "1", "rx": "2"}, {"t": "234werewrwr", "x": "2", "rx": "1"}]}', 'create_time' => '2022-05-06 10:05:47', 'update_time' => '2022-05-13 07:22:09'],
    ['id' => 2, 'sign' => 'array', 'name' => '数组', 'type' => 2, 'config_info' => '[{"extra": [], "field": "", "title": "", "formType": ""}]', 'config_value' => '[{"value": "asdad"}, {"value": "adsasd"}, {"value": "asdasdad"}, {"value": "asdasdd"}]', 'create_time' => '2022-05-10 01:32:34', 'update_time' => '2022-05-10 08:21:24'],
    ['id' => 3, 'sign' => 'kayValuepair', 'name' => '键值对', 'type' => 3, 'config_info' => '[{"extra": [], "field": "", "title": "", "formType": ""}]', 'config_value' => '[{"label": "qwe", "value": "qwe"}, {"label": "qwewqe", "value": "qweqwe"}, {"label": "adsas", "value": "asdads"}, {"label": "123", "value": "123"}]', 'create_time' => '2022-05-10 01:34:03', 'update_time' => '2022-05-13 07:22:33'],
])]
class SuperConfig extends Model
{

    protected $schema = [
        'id'           => 'int',
        'sign'         => 'varchar',
        'name'         => 'varchar',
        'type'         => 'tinyint',
        'config_info'  => 'json',
        'config_value' => 'json',
        'create_time'  => 'datetime',
        'update_time'  => 'datetime',
        'delete_time'  => 'int',
    ];


    protected $field = ['sign', 'name', 'type', 'config_info', 'config_value',];

    protected $type = [
        ...self::DEFAULT_CASTS,
        'config_info'  => 'array',
        'config_value' => 'array',
    ];
}
